package payClient

import (
	"context"
	"errors"

	"gitee.com/liuxuezhan/ar-platform/pay-channel-packet/payClient/adapter"
	"gitee.com/liuxuezhan/ar-platform/pay-channel-packet/payClient/dto"
	"gitee.com/liuxuezhan/ar-platform/pay-channel-packet/payClient/interfaceP"
)

type PayClient struct {
	cExt any
}

var _ interfaceP.PayInterface = (*PayClient)(nil)

func NewPayClient() *PayClient {
	return &PayClient{}
}

func (c *PayClient) WithChannelExt(cExt any) {
	c.cExt = cExt
}

func (c *PayClient) Pay(ctx context.Context, req dto.PayRequestDto) (dto.PayResponseDto, error) {
	productor := adapter.GenProductor(req.Channel.Channel)
	if productor == nil {
		return dto.PayResponseDto{}, errors.New("Not found")
	}

	return productor.AdapterPay(ctx, req)
}

func (c *PayClient) PayNotify(req dto.PayNotifyReqDto) (dto.PayNotifyRespDto, error) {
	productor := adapter.GenProductor(req.Channel.Channel)
	if productor == nil {
		return dto.PayNotifyRespDto{}, errors.New("Not found")
	}
	return productor.AdapterPayNotify(req)
}

func (c *PayClient) Withdraw(ctx context.Context, req dto.WithdrawRequestDto) (dto.WithdrawResponseDto, error) {
	productor := adapter.GenProductor(req.Channel.Channel)
	if productor == nil {
		return dto.WithdrawResponseDto{}, errors.New("Not found")
	}

	productor.WithOption()

	return productor.AdapterWithdraw(ctx, req)
}

func (c *PayClient) WithdrawNotify(req dto.WithdrawNotifyReqDto) (dto.WithdrawNotifyRespDto, error) {
	productor := adapter.GenProductor(req.Channel.Channel)
	if productor == nil {
		return dto.WithdrawNotifyRespDto{}, errors.New("Not found")
	}
	return productor.AdapterWithdrawNotify(req)
}
